﻿#include "communicationitem.h"
#include "ui_communicationitem.h"

CommunicationItem::CommunicationItem(const QString &email,const QString &name,const QString &newInfo,QWidget *parent) :
    QWidget(parent)
    ,ui(new Ui::CommunicationItem)
    , email(email)
{
    ui->setupUi(this);
    ui->name_LB->setText(name);
    ui->newInfo_LB->setText(newInfo);
    setHeadImg();
}
CommunicationItem::CommunicationItem(const QString &email,const QString &name,const QString &newInfo,const QString &time,QWidget *parent):
    QWidget(parent)
    , ui(new Ui::CommunicationItem)
    , email(email)
{
    ui->setupUi(this);
    ui->name_LB->setText(name);
    ui->newInfo_LB->setText(newInfo);
    ui->newDate_LB->setText(time);
    setHeadImg();
    connect(ui->close_BT,&QPushButton::clicked,[this](){
        emit closeClicked(this,cpage);
    });
}

CommunicationItem::~CommunicationItem()
{
    delete ui;
}

QString CommunicationItem::getEmail(){
    return email;
}

QString CommunicationItem::getUsername(){
    return ui->name_LB->text();
}

QWidget* CommunicationItem::getPage(){
    return this->cpage;
}


void CommunicationItem::setPage(QWidget* cpage){
    this->cpage=cpage;
}

void CommunicationItem::setHeadImg(){
    ui->img_LB->setStyleSheet(QString("\
        #img_LB{\
            border-radius:25px;\
            border-image:url('./accountData/Res/%1/headImg/head.png') 0 0 0 0 stretch stretch;\
        }\
    ").arg(email));
}

void CommunicationItem::setNewInfo(QString text,QString newDate){
    ui->newInfo_LB->setText(text);
    ui->newDate_LB->setText(newDate);
}

void CommunicationItem::mousePressEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton)
    {
        emit clicked(this,cpage);
    }
}

void CommunicationItem::setNormalStyle(){
    ui->CommunicationItem_content->setStyleSheet(R"(
        #CommunicationItem_content:hover{
            background-color:rgb(216, 215, 215);
        }
    )");
}

void CommunicationItem::setClickedStyle(){
    ui->CommunicationItem_content->setStyleSheet(R"(
            #CommunicationItem_content{
                background-color:rgb(200, 198, 197);
            }
    )");
}

